package com.roger.myHome.service.impl;

import com.roger.myHome.entity.qto.LoanRry;
import com.roger.myHome.entity.vo.LoanVo;
import com.roger.myHome.mapper.LoanMapper;
import com.roger.myHome.page.EUDataGridResult;
import com.roger.myHome.service.LoanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Service
public class LoanServiceImpl implements LoanService {
    @Resource
    private LoanMapper loanMapper;

    @Override
    public EUDataGridResult page(LoanRry req) {

        List<LoanVo> page = loanMapper.page(req);
        setResult(page);


        return new EUDataGridResult(page, loanMapper.totalSize(req));
    }

    private void setResult (List<LoanVo> page) {
        for (LoanVo vo : page) {
            if (vo.getCost() != null) {
                BigDecimal c = vo.getCost().divide(vo.getRepaymentMoney(),2, BigDecimal.ROUND_HALF_UP);
                vo.setRate(c);
            }
        }
    }
}
